package XYC;

import static org.junit.Assert.assertTrue;
import XYC.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that YichiSpecialBot beats 
 * Wall with more than 50% chance.
 * @author Yichi Xu
 *
 */
public class TestYichiSpecialBotVersusWall extends RobotTestBed {
  /** Check that we win at least 50% of the time. */
  private static final double WIN_RATE = 0.5;
  /**
   * Specifies that Wall and YichiSpecialBot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Walls,XYC.YichiSpecialBot";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that YichiSpecialBot 
   * has more than 50% chance to win against Wall.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    
    // Check to make sure YichiSpecialBot won more than 50% of the time
    double winRate = (double) results[1].getFirsts() / (double) getNumRounds();
    assertTrue("Check YichiSpecialBot winning rate", winRate >= WIN_RATE);
  }
}
